package o;

import android.text.TextUtils;
import android.widget.TextView;

public abstract class eva {
    public static String ˊ(String str) {
        if (str.endsWith("\r\n")) {
            str = str.substring(0, str.length() - "\r\n".length());
        }
        if (str.endsWith("\n")) {
            return str.substring(0, str.length() - "\n".length());
        }
        return str;
    }

    public static String ˊ(int i, TextView textView) {
        if (i <= 0) {
            return "";
        }
        int lineCount = textView.getLineCount();
        if (lineCount <= 0) {
            return "";
        }
        Object charSequence = textView.getText().toString();
        if (TextUtils.isEmpty(charSequence)) {
            return "";
        }
        if (i > lineCount) {
            i = lineCount;
        }
        return charSequence.substring(0, textView.getLayout().getLineEnd(i - 1));
    }

    public static String ˏ(int i, TextView textView, String str) {
        if (i <= 0) {
            return "";
        }
        int lineCount = textView.getLineCount();
        if (lineCount <= 0) {
            return "";
        }
        Object charSequence = textView.getText().toString();
        if (TextUtils.isEmpty(charSequence)) {
            return "";
        }
        int i2 = i - 1;
        if (i2 >= lineCount) {
            lineCount--;
        } else {
            lineCount = i2;
        }
        i2 = 0;
        if (lineCount - 1 >= 0) {
            try {
                i2 = textView.getLayout().getLineEnd(lineCount - 1);
            } catch (Throwable e) {
                Logger.ˋ(str, "getLineString error", e);
                return "";
            }
        }
        return charSequence.substring(i2, textView.getLayout().getLineEnd(lineCount));
    }
}
